package com.cql.web.controller.business;

import com.cql.common.core.DTO.CommentDTO;
import com.cql.common.core.DTO.CommentParamDTO;
import com.cql.common.core.base.AjaxResult;
import com.cql.common.core.base.BaseController;
import com.cql.framework.config.security.service.TokenService;
import com.cql.service.business.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @author cql
 */
@RestController
@RequestMapping("/comment")
public class CommentController extends BaseController {

    @Autowired
    private CommentService commentService;

    @Autowired
    private TokenService tokenService;


    /**
     * 发表评论
     *
     * @param paramDTO
     * @param request
     * @return
     */
    @PostMapping
    public AjaxResult sendComment(@RequestBody CommentParamDTO paramDTO, HttpServletRequest request) {
        Long userId = tokenService.getLoginUser(request).getUserDO().getUserId();
        paramDTO.setFromUser(userId);
        CommentDTO commentDTO = commentService.insertComment(paramDTO);
        return AjaxResult.success(commentDTO);
    }


}
